package com.etc.config;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

/**
 * @author Chen
 * @since 2021/1/13 - 23:41
 */
@WebListener
public class DriverMangerListner implements ServletContextListener {

	public void contextInitialized(ServletContextEvent sce) {

	}

	public void contextDestroyed(ServletContextEvent sce) {
		SchedulerFactory schedulerFactory = new StdSchedulerFactory();
		try {
			Scheduler scheduler = schedulerFactory.getScheduler();
			scheduler.shutdown(true);
		} catch (SchedulerException e) {
			e.printStackTrace();
		}

// jdbc mysql8
//		com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.uncheckedShutdown();
		Enumeration<Driver> enumeration = DriverManager.getDrivers();
		while (enumeration.hasMoreElements()) {
			try {
				DriverManager.deregisterDriver(enumeration.nextElement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}